package com.xm_jd.controller.dd;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xm_jd.model.dao.Index1Dao;
import com.xm_jd.model.dao.NewDao;
import com.xm_jd.model.entitys.GoodsDetailVO;
import com.xm_jd.model.entitys.IndexVO;
import com.xm_jd.model.entitys.user;
import com.xm_jd.utils.BaseServlet;

/**
 * Servlet implementation class index1
 */
@WebServlet("/index1")
public class index1 extends BaseServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public index1() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		user aa=(user) request.getSession().getAttribute("users");
		List<IndexVO> sp = new Index1Dao().getOrderId(aa.getUser_id());
	
		System.out.println(aa.getUser_id());

		
		
		Map<Integer, List<IndexVO>> map = new HashMap<>();
		for (IndexVO i : sp) {
			List<IndexVO> tmp = new Index1Dao().getselectsp(i.getDd_id());
			map.put(i.getDd_id(), tmp);
		}
		
		//获取订单的id
		String dd = request.getParameter("id");
		//修改订单状态
		new Index1Dao().updatezt(dd);
		
		if(sp.size()>0){
			request.setAttribute("sp", sp);
			request.setAttribute("map", map);
		}
		//request.getRequestDispatcher("jsps/dd/dd_index1.jsp").forward(request, response);
		this.forward("dd/dd_index1");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
